//-------------------------------页面初始化开始-----------------------------------------------
Ext.onReady(function(){
    // 树形配置开始
    var tree = new Ext.tree.TreePanel({
	    loader: new Ext.tree.TreeLoader(),
        title: '系统管理',
        split: true,
        border: true,
		rootVisible:false,
        collapsible: true,
        width: 120,
        minSize: 80,
        maxSize: 200
    });
	
	//单击树事件开始
	tree.on("click",function(node,event){
		if(!node.isLeaf()){return;}
		event.stopEvent();
		var n = tabpanel.getComponent(node.id);
		var k  = tabpanel.find('title',node.text);
		if(n || k!=''){tabpanel.setActiveTab(node.id);return}
		//生成右侧的网点管理、图标管理等数据
		switch(node.id){
			case "customerInfo":	//企业网点管理开始
				//alert(node.text);
				var hall_grid_n = tabs.add(grid_customerInfo);
				tabs.setActiveTab(hall_grid_n);
				customerInfo_search.load({
					params:{
						start: 0,
						limit:20
					}
					,callback:function(r,options,success){if(customerInfo_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				});
				break;
			case "saleAreaTree":	//企业网点管理开始
				//alert(node.text);
				var saleArea_grid_n = tabs.add(grid_saleArea);
				tabs.setActiveTab(saleArea_grid_n);
				saleArea_search.load({
					params:{
						start: 0,
						limit:20
					}
					,callback:function(r,options,success){if(saleArea_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				});
				break;	
			case "wangdianTree":	//网点管理开始
				//alert(node.text);
				var wangdian_grid_n = tabs.add(grid_wangdian);
				tabs.setActiveTab(wangdian_grid_n);
				wangdian_search.load({
					params:{
						start: 0,
						limit:20
					}
					,callback:function(r,options,success){if(wangdian_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				});
				break;
			case "departmentTree":	//部门管理开始
				//alert(node.text);
				var department_grid_n = tabs.add(grid_department);
				tabs.setActiveTab(department_grid_n);
				department_search.load({
					params:{
						start: 0,
						limit:20
					}
					,callback:function(r,options,success){if(department_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				});
				break;
			case "positionTree":	//职位管理开始
				//alert(node.text);
				var position_grid_n = tabs.add(grid_position);
				tabs.setActiveTab(position_grid_n);
				position_search.load({
					params:{
						start: 0,
						limit:20
					}
					,callback:function(r,options,success){if(position_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				});
				break;
			case 'out':location.href="login.asp";break;//11054572,3561267
			default:break;
		}
    });
	
	//单击树事件结束
	var root = new Ext.tree.AsyncTreeNode({
		text:'',
		children: [
			{text:'客户信息管理',id:'customerInfo',leaf:true},
			{text:'销售片区管理',id:'saleAreaTree',leaf:true},
			{text:'网点信息管理',id:'wangdianTree',leaf:true},
			{text:'部门管理',id:'departmentTree',leaf:true},
			{text:'职位管理',id:'positionTree',leaf:true},
			{text:'退出系统',id:'out',leaf:true}
		]
	});
    tree.setRootNode(root);
    tree.expand();
    // 树形配置结束
    
	//查询TAB
	var tabpanel=new Ext.TabPanel({
        activeTab:0,    //设置默认选择的选项卡
        width:300,
		height:700
		//,items:[grid,form]
    });
	//查询TAB结束
	
	//管理TAB开始
	var tabs = new Ext.TabPanel({
        //renderTo: 'tab',
        height: 100,
		region:'center',
		loadMask: true,
		//closable: true,
        enableTabScroll: true
    });
    tabs.add({
        title: '说明',
		   el:'shuoming'
        //html: '内容1'
    });
    tabs.activate(0);
	//管理TAB结束
	
    // 布局开始
    var viewport = new Ext.Viewport({
        layout:'border',
        items:[{
				region: 'north',
				contentEl: 'north-div',
				height: 55,
				bodyStyle: 'background-color:#BBCCEE;'
			},{
				region: 'south',
				contentEl: 'south-div',
				height: 20,
				bodyStyle: 'background-color:#BBCCEE;'
			},{ region: 'west',
				split: true,
				layout:'accordion',
				width:300,
				collapsible:true,
				title:'系统菜单',
				items:[tree]
			},tabs
		]
    });
    // 布局结束
});
//--------------------------------页面初始化结束-----------------------------------------------


//--------------------------------客户信息管理开始--------------------------------------------------
var customerInfo_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var customerInfo_cm = new Ext.grid.ColumnModel([customerInfo_sm,
	{header:'编号',dataIndex:'id',hidden:true},
	{header:'客户名称',dataIndex:'customerName'},
	{header:'客户办公地址',dataIndex:'customerOfficeAdress'},
	{header:'客户办公地址经度',dataIndex:'customerOfficeAdressLng'},
	{header:'客户办公地址纬度',dataIndex:'customerOfficeAdressLat'},
	{
		header:'客户仓库地址',
		dataIndex:'customerStoreHouse'
		//,
//			renderer:function(value){
//				return entTypeDes(value);
//			}
	},
	{header:'客户仓库地址纬度',dataIndex:'customerStoreHouseLng'},
	{header:'客户仓库地址纬度',dataIndex:'customerStoreHouseLat'},
	{header:'所属城市',dataIndex:'province'},
	{header:'市',dataIndex:'city',hidden:true},
	{header:'区',dataIndex:'district',hidden:true},
	{header:'客户辖区',dataIndex:'kehuxiaqu'},
	{header:'客户负责人',dataIndex:'kehufuzeren'},
	{header:'客户负责人联系方式',dataIndex:'kehufuzerenTel'},
	{header:'备注信息',dataIndex:'beizhu'}
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_customerInfo = new Ext.data.HttpProxy({url:'json_customerInfoSearch.asp'});
var reader_customerInfo = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'customerName'},
		{name:'customerOfficeAdress'},
		{name:'customerOfficeAdressLng'},
		{name:'customerOfficeAdressLat'},
		{name:'customerStoreHouse'},
		{name:'customerStoreHouseLng'},
		{name:'customerStoreHouseLat'},
		{name:'province'},
		{name:'city'},
		{name:'district'},
		{name:'kehuxiaqu'},
		{name:'kehufuzeren'},
		{name:'kehufuzerenTel'},
		{name:'beizhu'}
	]
);
//构建Store
customerInfo_search = new Ext.data.Store({
	proxy:proxy_customerInfo,
	reader:reader_customerInfo
/*		,
	baseParams:{limit:5}*/
});

var grid_customerInfo = new Ext.grid.GridPanel({
	store: customerInfo_search,
	cm: customerInfo_cm,
	loadMask: true,
	//closable: true,
	title: '客户信息列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:customerInfo_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'customerKeyWord',name:'customerKeyWord',allowBlank: true,emptyText: "搜索客户名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				customerInfo_search.removeAll();
				customerInfo_search.load({
					params:{
						start: 0,
						limit:20,
						customerKeyWord:grid_customerInfo.getTopToolbar().findById("customerKeyWord").getValue()
					},callback:function(r,options,success){if(customerInfo_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{
			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				hall_form_obj = getCustomerInfoForm();
				customerInfo_win = new Ext.Window({title: "添加客户信息",width: 650,height: 440,modal: true,maximizable:false,resizable:false,items: hall_form_obj});
				customerInfo_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				var row = grid_customerInfo.getSelectionModel().getSelections();
				if (!row){return;}
				for (var i = 0; i < row.length; i++)
				{
					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
					hall_form_obj = getCustomerInfoForm(row[i]);
					customerInfo_win = new Ext.Window({title: "修改客户信息",width: 650,height: 440,modal: true,maximizable:false,resizable:false,items: hall_form_obj});
					customerInfo_win.show();
					//field = hall_form_obj.getForm().findField('icon');
					//field.setValue(row[i].get("icon"));//new
					//alert(row[i].get("icon"))
				}
			}
		},
		{xtype: "tbseparator"}, 
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_customerInfo.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_customerInfoDelete.asp',
									params: 'id=' + row[i].get("id")
								});
							}
							customerInfo_search.removeAll();
							customerInfo_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		}
	]
});

//生成新加机构点的菜单
function getCustomerInfoForm(row)
{
	//网点数据结束
	return new Ext.FormPanel({
		id: 'hall_form',
		name: 'hall_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 640,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		items: [
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'customerName',fieldLabel: '客户名称',width:150,allowBlank:false,blankText: '客户名称不能为空',value:(row?row.get("customerName"):"")},	//行1
			{xtype: 'button',handler:function(){citysWin(cityOptions);}, name: 'province_city_district',id:"province_city_district",fieldLabel: '选择城市',text:'选择',width: 120,height:22},
			{ // 行2
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						labelWidth: 120,
						items: [{xtype: 'textfield',name:'province',id:'province',fieldLabel: '所在城市',width: 150,allowBlank:false,blankText: '省不能为空',value:(row?row.get("province"):"")}]
					},
					{
						hidden:true,
						//columnWidth: .33,
						layout: "form",
						labelWidth: 60,
						items: [{xtype: 'textfield',name:'city',id:'city',fieldLabel: '市',width: 70,value:(row?row.get("city"):"")}]
					},
					{
						hidden:true,
						//columnWidth: .33,
						layout: "form",
						labelWidth: 12,
						items: [{xtype: 'textfield',name:'district',id:'district',fieldLabel: '区',width: 70,value:(row?row.get("district"):"")}]
					}
				]
			},
			{ //行3
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5, // 该列有整行中所占百分比
						layout: "form", // 从上往下的布局
						labelWidth: 120,
						items: [{xtype: 'textfield',name:'customerOfficeAdress',fieldLabel: '客户办公地址',width: 150,allowBlank:false,blankText: '客户办公地址不能为空',value:(row?row.get("customerOfficeAdress"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						labelWidth: 120,
						items: [{xtype: 'button',handler:function(){showWin_Lnglat(setOfficeAddressLnglat);}, name: 'latlng_OfficeAdress',id:"hall_ezmarker_OfficeAdress",fieldLabel: '客户办公位置',text:'地图标注',width: 120,height:22}]
					}
				]
			},
			{ // 行4
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'customerOfficeAdressLng',id:'customerOfficeAdressLng',fieldLabel: '客户办公地址经度',width: 150,allowBlank:false,blankText: '经度不能为空',value:(row?row.get("customerOfficeAdressLng"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						items: [{xtype: 'textfield',name:'customerOfficeAdressLat',id:'customerOfficeAdressLat',fieldLabel: '客户办公地址纬度',width: 150,allowBlank:false,blankText: '纬度不能为空',value:(row?row.get("customerOfficeAdressLat"):"")}]
					}
				]
			},
			
			{ // 行5
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'customerStoreHouse',fieldLabel: '客户仓库地址',width: 150,allowBlank:false,blankText: '客户仓库地址不能为空',value:(row?row.get("customerStoreHouse"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						items: [{xtype: 'button',handler:function(){showWin_Lnglat(setStoreHouseLnglat);}, name: 'latlng_StoreHouse',id:"hall_ezmarker_StoreHouse",fieldLabel: '客户仓库位置',text:'地图标注',width: 120,height:22}]
					}
				]
			},
			{ // 行6
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'customerStoreHouseLng',id:'customerStoreHouseLng',fieldLabel: '客户仓库地址经度',width: 150,allowBlank:false,blankText: '经度不能为空',value:(row?row.get("customerStoreHouseLng"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						items: [{xtype: 'textfield',name:'customerStoreHouseLat',id:'customerStoreHouseLat',fieldLabel: '客户仓库地址纬度',width: 150,allowBlank:false,blankText: '纬度不能为空',value:(row?row.get("customerStoreHouseLat"):"")}]
					}
				]
			},
			{xtype: 'textfield',name:'kehuxiaqu',id:'kehuxiaqu',fieldLabel: '客户辖区',width: 150,allowBlank:false,blankText: '客户辖区不能为空',value:(row?row.get("kehuxiaqu"):"")},
			{xtype: 'textfield',name:'kehufuzeren',id:'kehufuzeren',fieldLabel: '客户负责人',width: 150,allowBlank:false,blankText: '客户负责人不能为空',value:(row?row.get("kehufuzeren"):"")},
			{xtype: 'textfield',name:'kehufuzerenTel',id:'kehufuzerenTel',fieldLabel: '客户负责人联系方式',width: 150,allowBlank:false,blankText: '客户负责人联系方式不能为空',value:(row?row.get("kehufuzerenTel"):"")},
			{xtype: 'textarea',fieldLabel: '备注信息',id: 'beizhu',anchor: '70%',name:'beizhu',height: 90,value:(row?row.get("beizhu"):"")}
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(customerInfo_win.getComponent('hall_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (customerInfo_win.getComponent('hall_form').form.isValid()) {
					customerInfo_win.getComponent('hall_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_customerInfo.asp',
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加客户信息成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改客户信息成功!');
								}
								customerInfo_win.getComponent('hall_form').form.reset();
								customerInfo_search.load({params: {start: 0,limit:20}});
								customerInfo_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加客户信息失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改客户信息失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							customerInfo_search.load({params: {start: 0}});
							customerInfo_win.getComponent('hall_form').form.reset();
							//customerInfo_win.getComponent('hall_form').findById("hall_ezmarker").reset();
						}
						
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				customerInfo_win.close();
			}
		}]
	});
}

//客户信息管理城市列表窗口
/*function customerCitysWin()
{
	citys_form_obj = citysForm(cityOptions);
	customerCitys_win = new Ext.Window({title: "城市列表",width: 213,height:375,modal: true,maximizable: false,resizable:false,items: citys_form_obj});
	customerCitys_win.show();
}*/
//给客户的所属城市赋值
function cityOptions(cityArr)
{
	Ext.getDom("province").value = "";
	for(var i=cityArr.length-1;i>=0;i--)
	{
		if(cityArr[i]!="root"&&cityArr[i]!="全国")
		{
			Ext.getDom("province").value += cityArr[i];//设定经度
		}
	}
}

//地图标注方法
var ezmarkerEvent = null;
function showWin_Lnglat(fun)
{
	//ezmarker.win.config.canClose = 1;
	//ezmarker.createWin(ezmarker.win.config);
	ezmarker.setWinZIndex(100000);
	//ezmarker.win.setContainerSize([650,450]);	//设置标注层的大小
	var ezmarkerDiv = document.getElementById("ezmarkerDiv");
	ezmarkerDiv.style.cssText = "position:absolute;width:650;height:450;left:50%;top:50%;margin-left:-325px;margin-top:-225px;z-index:100000;display:block";
	
	ezmarkerEvent = LTEvent.addListener(ezmarker,"mark",fun);	//在每次用户完成标注的时候执行check函数
}
//设置客户办公地址经纬度
function setOfficeAddressLnglat(point,zoom)
{
	LTEvent.removeListener(ezmarkerEvent);
	Ext.getDom("customerOfficeAdressLng").value = point.getLongitude();
	Ext.getDom("customerOfficeAdressLat").value = point.getLatitude();
	document.getElementById("ezmarkerDiv").style.display = "none";
}
//设置客户仓库地址经度
function setStoreHouseLnglat(point,zoom)
{
	LTEvent.removeListener(ezmarkerEvent);
	Ext.getDom("customerStoreHouseLng").value = point.getLongitude();
	Ext.getDom("customerStoreHouseLat").value = point.getLatitude();
	document.getElementById("ezmarkerDiv").style.display = "none";
}
//--------------------------------客户信息管理结束-------------------------------------------------	


//--------------------------------销售片区管理开始-------------------------------------------------	
var saleArea_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var saleArea_cm = new Ext.grid.ColumnModel([saleArea_sm,
	{header:'编号',dataIndex:'id',hidden:true},
	{header:'销售片区名称',dataIndex:'saleAreaName'},
	{header:'销售片区范围',dataIndex:'salerId'},
	{header:'销售片区面积',dataIndex:'saleArea'},
	{header:'销售片区颜色',dataIndex:'areaColor'},
	{header:'类别',dataIndex:'areaGrade',
		renderer:function(value){
			return "一级片区";
		}
	},
	{header:'上一级片区',dataIndex:'owenArea',hidden:true},
	{header:'下属片区',dataIndex:'addSecondSaleArea',width:100,renderer:addSecondSaleArea}
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_saleArea = new Ext.data.HttpProxy({url:'json_saleAreaSearch.asp?saleType=1'});
var reader_saleArea = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'saleAreaName'},
		{name:'salerId'},
		{name:'saleArea'},
		{name:'areaColor'},
		{name:'areaGrade'},
		{name:'owenArea'}
	]
);
//构建Store
saleArea_search = new Ext.data.Store({
	proxy:proxy_saleArea,
	reader:reader_saleArea
});

var grid_saleArea = new Ext.grid.GridPanel({
	store: saleArea_search,
	cm: saleArea_cm,
	loadMask: true,
	//closable: true,
	title: '销售片区列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:saleArea_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'saleAreaNameKeyWord',name:'saleAreaNameKeyWord',allowBlank: true,emptyText: "搜索销售片区名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				saleArea_search.removeAll();
				saleArea_search.load({
					params:{
						start: 0,
						limit:20,
						saleAreaNameKeyWord:grid_saleArea.getTopToolbar().findById("saleAreaNameKeyWord").getValue()
					},callback:function(r,options,success){if(saleArea_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{
			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				saleArea_form_obj = getSaleAreaForm();
				saleArea_win = new Ext.Window({title: "添加销售片区",width: 360,height: 210,modal: true,maximizable:false,resizable:false,items: saleArea_form_obj});
				saleArea_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				var row = grid_saleArea.getSelectionModel().getSelections();
				if (!row){return;}
				for (var i = 0; i < row.length; i++)
				{
					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
					saleArea_form_obj = getSaleAreaForm(row[i]);
					saleArea_win = new Ext.Window({title: "修改销售片区",width: 360,height: 270,modal: true,maximizable:false,resizable:false,items: saleArea_form_obj});
					saleArea_win.show();
					//field = hall_form_obj.getForm().findField('icon');
					//field.setValue(row[i].get("icon"));//new
					//alert(row[i].get("icon"))
				}
			}
		},
		{xtype: "tbseparator"},
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_saleArea.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_saleAreaDelete.asp?saleType=1',
									params: 'id=' + row[i].get("id")
								});
							}
							saleArea_search.removeAll();
							saleArea_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		}
	]
});

//生成新加机构点的菜单
function getSaleAreaForm(row)
{
	//网点数据结束
	return new Ext.FormPanel({
		id: 'saleArea_form',
		name: 'saleArea_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 350,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		items: [
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'saleAreaName',fieldLabel: '销售片区名称',width:150,allowBlank:false,blankText: '销售片区名称不能为空',value:(row?row.get("saleAreaName"):"")},
			{xtype: 'button',handler:function(){citysWin(saleAreaCityOptions,2);}, name: 'saleArea_ID',id:"saleArea_ID",fieldLabel: '销售片区',text:'请选择销售片区',width: 120,height:22},
			{xtype: 'textfield',name:'salerId',id:'salerId',fieldLabel: '销售片区范围',width: 150,allowBlank:false,blankText: '销售片区不能为空',value:(row?row.get("salerId"):"")},
			{xtype: 'textfield',name:'saleArea',id:'saleArea',fieldLabel: '销售片区面积',width: 150,allowBlank:false,blankText: '销售片区面积不能为空',value:(row?row.get("saleArea"):"")},
			{xtype: 'textfield',name:'areaColor',id:'areaColor',fieldLabel: '销售片区颜色',width: 150,allowBlank:false,blankText: '销售片区颜色不能为空',value:(row?row.get("areaColor"):"")},
			{hidden:true,xtype: 'hidden',name:'areaGrade',id:'areaGrade',fieldLabel: '类别',width: 150,value:(row?row.get("areaGrade"):1)},
			{hidden:true,xtype: 'hidden',name:'owenArea',id:'owenArea',fieldLabel: '上一级片区',width: 150,value:(row?row.get("owenArea"):"")}
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(customerInfo_win.getComponent('hall_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (saleArea_win.getComponent('saleArea_form').form.isValid()) {
					saleArea_win.getComponent('saleArea_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_saleArea.asp',
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加销售片区成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改销售片区成功!');
								}
								saleArea_win.getComponent('saleArea_form').form.reset();
								saleArea_search.load({params: {start: 0,limit:20}});
								saleArea_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加销售片区失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改销售片区失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							saleArea_search.load({params: {start: 0}});
							saleArea_win.getComponent('saleArea_form').form.reset();
							//customerInfo_win.getComponent('saleArea_form').findById("hall_ezmarker").reset();
						}
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				saleArea_win.close();
			}
		}]
	});
}

//给客户的所属城市赋值
function saleAreaCityOptions(cityArr)
{
	Ext.getDom("salerId").value = cityArr.join(",");
}
//--------------------------------销售片区管理结束-------------------------------------------------
//--------------------------------销售片区二级片区管理开始---------------------------------------------
//添加二级片区
function addSecondSaleArea(value,cellmeta,record,rowIndex,columnIndex,store)
{
	var str="<input type='button' value='添加二级片区' onclick='secondSaleAreaWin(\""+record.data["id"]+"\",\""+record.data["saleAreaName"]+"\")'\>"
	//alert(str);
	return str;
}

function secondSaleAreaWin(id,saleAreaName)
{
	secondSaleArea_form_obj = secondSaleAreaForm(id,saleAreaName);
	secondSaleArea_win = new Ext.Window({title: "二级片区列表",width: 664,height:500,modal: true,maximizable: false,resizable:false,items: secondSaleArea_form_obj});
	secondSaleArea_win.show();
}
function secondSaleAreaForm(id,saleAreaName)
{
	var form1 = new Ext.form.FormPanel({
		width:650,
		height:480,
		region:'center',
		loadMask: true,
		//closable: true,
        enableTabScroll: true,
		//frame:true,//圆角和浅蓝色背景
		//renderTo:Ext.getBody(),//呈现
		//title:"FormPanel",
		//bodyStyle:"padding:5px 5px 0",
		//defaults:{xtype:"textfield",width:120},
		items:[
			secondSaleAreaFormPanel(id,saleAreaName)
		]
	});
	return form1;
}
function secondSaleAreaFormPanel(id,saleAreaName)
{
	var saleArea_sm_second = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
	var saleArea_cm_second = new Ext.grid.ColumnModel([saleArea_sm_second,
		{header:'编号',dataIndex:'id',hidden:true},
		{header:'销售片区名称',dataIndex:'saleAreaName'},
		{header:'销售片区范围',dataIndex:'salerId'},
		{header:'销售片区面积',dataIndex:'saleArea'},
		{header:'销售片区颜色',dataIndex:'areaColor'},
		{header:'类别',dataIndex:'areaGrade',
			renderer:function(value){
				return "二级片区";
			}
		},
		{header:'上一级片区',dataIndex:'owenArea'}
	]);
	//start 读取远程POI JSON数据显示在表格里
	var proxy_saleArea_second = new Ext.data.HttpProxy({url:'json_saleAreaSearch.asp?saleType=2'});
	var reader_saleArea_second = new Ext.data.JsonReader(
		{
			totalProperty:'mytotal',//记录总数
			root:'root',
			id:'id'
		},[
			{name:'id'},
			{name:'saleAreaName'},
			{name:'salerId'},
			{name:'saleArea'},
			{name:'areaColor'},
			{name:'areaGrade'},
			{name:'owenArea'},
			{name:'saleAreaLv1'}
		]
	);
	//构建Store
	saleArea_search_second = new Ext.data.Store({
		proxy:proxy_saleArea_second,
		reader:reader_saleArea_second
	});
	
	var grid_saleArea_second = new Ext.grid.GridPanel({
		store: saleArea_search_second,
		cm: saleArea_cm_second,
		loadMask: true,
		width:650,
		height:468,
		//closable: true,
		//title: '销售片区列表',
		bbar: new Ext.PagingToolbar({
			pageSize:20,
			store:saleArea_search_second,
			displayInfo:true,
			//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
			displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
			emptyMsg:'没有记录',
			beforePageText: "第",
			afterPageText:"页 共{0}页"
		}),
		tbar: [
			{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'saleAreaNameKeyWord_second',name:'saleAreaNameKeyWord_second',allowBlank: true,emptyText: "搜索销售片区名称"},
			{xtype: "tbseparator"},
			{
				text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
				handler: function(){
					//Ext.Msg.alert('提示','目前无数据');
					saleArea_search_second.removeAll();
					saleArea_search_second.load({
						params:{
							start: 0,
							limit:20,
							owenAreaId:id,
							saleAreaNameKeyWord:grid_saleArea_second.getTopToolbar().findById("saleAreaNameKeyWord_second").getValue()
						},callback:function(r,options,success){if(saleArea_search_second.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
					})
				}
			},
			{
				text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
				handler: function(){
					Ext.QuickTips.init();//开启表单提示
					saleArea_form_obj = getSaleAreaSecondForm(id,saleAreaName);
					secondSaleArea_win = new Ext.Window({title: "添加销售片区",width: 360,height: 210,modal: true,maximizable:false,resizable:false,items: saleArea_form_obj});
					secondSaleArea_win.show();
				}
			},
			{xtype: "tbseparator"},
			{
				text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
				handler: function(){
					Ext.QuickTips.init();//开启表单提示
					var row = grid_saleArea_second.getSelectionModel().getSelections();
					if (!row){return;}
					for (var i = 0; i < row.length; i++)
					{
						Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
						saleArea_form_obj = getSaleAreaSecondForm(id,saleAreaName,row[i]);
						secondSaleArea_win = new Ext.Window({title: "修改销售片区",width: 360,height: 270,modal: true,maximizable:false,resizable:false,items: saleArea_form_obj});
						secondSaleArea_win.show();
						//field = hall_form_obj.getForm().findField('icon');
						//field.setValue(row[i].get("icon"));//new
						//alert(row[i].get("icon"))
					}
				}
			},
			{xtype: "tbseparator"},
			{
				text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
				handler: function(){
					var row = grid_saleArea_second.getSelectionModel().getSelections();
					if (row) {
						Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
							if (butten == "yes") {
								for (var i = 0; i < row.length; i++) {
									//alert(row[i].get("id"));
									Ext.Ajax.request({
										url: 'json_saleAreaDelete.asp?saleType=2',
										params: 'id=' + row[i].get("id")
									});
								}
								saleArea_search_second.removeAll();
								saleArea_search_second.load({params: {start:0,limit:20,owenAreaId:id}});
							}
						})
					}
				}
			}
		]
	});
	saleArea_search_second.load({params: {start:0,limit:20,owenAreaId:id}});
	return grid_saleArea_second;
}

//生成新加机构点的菜单
function getSaleAreaSecondForm(owenAreaId,saleAreaNameParam,row)
{
	//网点数据结束
	return new Ext.FormPanel({
		id: 'saleArea_Second_form',
		name: 'saleArea_Second_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 350,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		items: [
			{xtype: 'hidden',name:'owenAreaId',value:owenAreaId},
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'saleAreaNameSecond',fieldLabel: '销售片区名称',width:150,allowBlank:false,blankText: '销售片区名称不能为空',value:(row?row.get("saleAreaName"):"")},
			{xtype: 'button',handler:function(){citysWin(saleAreaSecondCityOptions,2);}, name: 'saleAreaSecond_ID',id:"saleAreaSecond_ID",fieldLabel: '销售片区',text:'请选择销售片区',width: 120,height:22},
			{xtype: 'textfield',name:'salerIdSecond',id:'salerIdSecond',fieldLabel: '销售片区范围',width: 150,allowBlank:false,blankText: '销售片区不能为空',value:(row?row.get("salerId"):"")},
			{xtype: 'textfield',name:'saleAreaSecond',id:'saleAreaSecond',fieldLabel: '销售片区面积',width: 150,allowBlank:false,blankText: '销售片区面积不能为空',value:(row?row.get("saleArea"):"")},
			{xtype: 'textfield',name:'areaColorSecond',id:'areaColorSecond',fieldLabel: '销售片区颜色',width: 150,allowBlank:false,blankText: '销售片区颜色不能为空',value:(row?row.get("areaColor"):"")},
			{hidden:true,xtype: 'hidden',name:'areaGradeSecond',id:'areaGradeSecond',fieldLabel: '类别',width: 150,value:(row?row.get("areaGrade"):1)},
			{hidden:true,xtype: 'hidden',name:'owenAreaSecond',id:'owenAreaSecond',fieldLabel: '上一级片区',width: 150,value:saleAreaNameParam}
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(customerInfo_win.getComponent('hall_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (secondSaleArea_win.getComponent('saleArea_Second_form').form.isValid()) {
					secondSaleArea_win.getComponent('saleArea_Second_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_saleAreaSecond.asp',
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加销售片区成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改销售片区成功!');
								}
								secondSaleArea_win.getComponent('saleArea_Second_form').form.reset();
								saleArea_search_second.load({params: {start: 0,limit:20,owenAreaId:owenAreaId}});
								secondSaleArea_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加销售片区失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改销售片区失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							saleArea_search_second.load({params: {start:0,limit:20,owenAreaId:owenAreaId}});
							secondSaleArea_win.getComponent('saleArea_Second_form').form.reset();
							//customerInfo_win.getComponent('saleArea_Second_form').findById("hall_ezmarker").reset();
						}
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				secondSaleArea_win.close();
			}
		}]
	});
}

//给客户的所属城市赋值
function saleAreaSecondCityOptions(cityArr)
{
	Ext.getDom("salerIdSecond").value = cityArr.join(",");
}
//--------------------------------销售片区二级片区管理结束---------------------------------------------


//--------------------------------网点信息管理开始-------------------------------------------------	

var wangdian_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var wangdian_cm = new Ext.grid.ColumnModel([wangdian_sm,
	{header:'编号',dataIndex:'id',hidden:true},
	{header:'网点名称',dataIndex:'wangdianName'},
	{header:'网点所属客户',dataIndex:'wangdianOwen'},
	{header:'所属城市',dataIndex:'province'},
	{header:'市',dataIndex:'city',hidden:true},
	{header:'区',dataIndex:'district',hidden:true},
	{header:'网点地址',dataIndex:'wangdianAddress'},
	{header:'网点地址地图标注经度',dataIndex:'wangdianAddressLng'},
	{header:'网点地址地图标注纬度',dataIndex:'wangdianAddressLat'},
	{header:'网点所属片区',dataIndex:'wangdianAreaOwen'},
	{header:'网点负责人',dataIndex:'wangdianfuzeren'},
	{header:'网点负责人联系方式',dataIndex:'wdfzrTel'},
	{header:'网点业务人员',dataIndex:'wangdianyewuren'},
	{header:'网点业务人联系方式',dataIndex:'wdywrTel'},
	{header:'网点图片路径',dataIndex:'wangdianPhoto'},
	{header:'备注信息',dataIndex:'beizhu'}
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_wangdian = new Ext.data.HttpProxy({url:'json_wangdianInfoSearch.asp'});
var reader_wangdian = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'wangdianName'},
		{name:'wangdianOwen'},
		{name:'province'},
		{name:'city'},
		{name:'district'},
		{name:'wangdianAddress'},
		{name:'wangdianAddressLng'},
		{name:'wangdianAddressLat'},
		{name:'saleAreaId'},
		{name:'wangdianAreaOwen'},
		{name:'wangdianfuzeren'},
		{name:'wdfzrTel'},
		{name:'wangdianyewuren'},
		{name:'wdywrTel'},
		{name:'wangdianPhoto'},
		{name:'beizhu'}
	]
);
//构建Store
wangdian_search = new Ext.data.Store({
	proxy:proxy_wangdian,
	reader:reader_wangdian
});

var grid_wangdian = new Ext.grid.GridPanel({
	store: wangdian_search,
	cm: wangdian_cm,
	loadMask: true,
	//closable: true,
	title: '网点信息列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:wangdian_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'wangdianNameKeyWord',name:'wangdianNameKeyWord',allowBlank: true,emptyText: "搜索网点名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				wangdian_search.removeAll();
				wangdian_search.load({
					params:{
						start: 0,
						limit:20,
						wangdianNameKeyWord:grid_wangdian.getTopToolbar().findById("wangdianNameKeyWord").getValue()
					},callback:function(r,options,success){if(wangdian_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{
			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				wangdian_form_obj = getwangdianForm();
				wangdian_win = new Ext.Window({title: "添加网点信息",width: 650,height: 440,modal: true,maximizable:false,resizable:false,items: wangdian_form_obj});
				wangdian_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				var row = grid_wangdian.getSelectionModel().getSelections();
				if (!row){return;}
				for (var i = 0; i < row.length; i++)
				{
					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
					wangdian_form_obj = getwangdianForm(row[i]);
					wangdian_win = new Ext.Window({title: "修改网点信息",width: 650,height: 440,modal: true,maximizable:false,resizable:false,items: wangdian_form_obj});
					wangdian_win.show();
					//field = hall_form_obj.getForm().findField('icon');
					//field.setValue(row[i].get("icon"));//new
					//alert(row[i].get("icon"))
				}
			}
		},
		{xtype: "tbseparator"},
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_wangdian.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_wangdianInfoSave.asp?sType=del',
									params: 'id=' + row[i].get("id")
								});
							}
							wangdian_search.removeAll();
							wangdian_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		}
	]
});


//生成新加机构点的菜单
function getwangdianForm(row)
{
	//网点数据结束
	return new Ext.FormPanel({
		id: 'wangdian_form',
		name: 'wangdian_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 640,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		items: [
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'wangdianName',fieldLabel: '网点名称',width:150,allowBlank:false,blankText: '网点名称不能为空',value:(row?row.get("wangdianName"):"")},	//行1
			{xtype: 'button',handler:function(){citysWin(cityOptions);}, name: 'province_city_district',id:"province_city_district",fieldLabel: '选择城市',text:'选择',width: 120,height:22},
			{ // 行2
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						labelWidth: 120,
						items: [{xtype: 'textfield',name:'province',id:'province',fieldLabel: '所在城市',width: 150,allowBlank:false,blankText: '省不能为空',value:(row?row.get("province"):"")}]
					},
					{
						hidden:true,
						//columnWidth: .33,
						layout: "form",
						labelWidth: 60,
						items: [{xtype: 'textfield',name:'city',id:'city',fieldLabel: '市',width: 70,value:(row?row.get("city"):"")}]
					},
					{
						hidden:true,
						//columnWidth: .33,
						layout: "form",
						labelWidth: 12,
						items: [{xtype: 'textfield',name:'district',id:'district',fieldLabel: '区',width: 70,value:(row?row.get("district"):"")}]
					}
				]
			},
			{ //行3
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5, // 该列有整行中所占百分比
						layout: "form", // 从上往下的布局
						labelWidth: 120,
						items: [{xtype: 'textfield',name:'wangdianAddress',fieldLabel: '网点地址',width: 150,allowBlank:false,blankText: '网点地址不能为空',value:(row?row.get("wangdianAddress"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						labelWidth: 120,
						items: [{xtype: 'button',handler:function(){showWin_Lnglat(wangdianAddressLnglat);}, name: 'latlng_wangdianAddress',id:"latlng_wangdianAddress",fieldLabel: '网点地址位置',text:'地图标注',width: 120,height:22}]
					}
				]
			},
			{ // 行4
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'wangdianAddressLng',id:'wangdianAddressLng',fieldLabel: '网点地址经度',width: 150,allowBlank:false,blankText: '经度不能为空',value:(row?row.get("wangdianAddressLng"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						items: [{xtype: 'textfield',name:'wangdianAddressLat',id:'wangdianAddressLat',fieldLabel: '网点地址纬度',width: 150,allowBlank:false,blankText: '纬度不能为空',value:(row?row.get("wangdianAddressLat"):"")}]
					}
				]
			},
			
			{ // 行5
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'wangdianOwen',fieldLabel: '网点所属客户',width: 150,allowBlank:false,blankText: '网点所属客户不能为空',value:(row?row.get("wangdianOwen"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						items: [{xtype: 'textfield',name:'wangdianAreaOwen',fieldLabel: '网点所属片区',width: 150,allowBlank:false,blankText: '网点所属片区不能为空',value:(row?row.get("wangdianAreaOwen"):"")}]
					}
				]
			},
			
			{ // 行6
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'wangdianfuzeren',fieldLabel: '网点负责人',width: 150,allowBlank:false,blankText: '网点负责人不能为空',value:(row?row.get("wangdianfuzeren"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						items: [{xtype: 'textfield',name:'wdfzrTel',fieldLabel: '网点负责人联系方式',width: 150,allowBlank:false,blankText: '网点负责人联系方式不能为空',value:(row?row.get("wdfzrTel"):"")}]
					}
				]
			},
			{ // 行7
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'wangdianyewuren',fieldLabel: '网点业务人',width: 150,allowBlank:false,blankText: '网点业务人员不能为空',value:(row?row.get("wangdianyewuren"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						items: [{xtype: 'textfield',name:'wdywrTel',fieldLabel: '网点业务人联系方式',width: 150,allowBlank:false,blankText: '网点业务人联系方式不能为空',value:(row?row.get("wdywrTel"):"")}]
					}
				]
			},
			{xtype: 'hidden',name:'saleId',value:(row?row.get("saleId"):"")},
			{xtype: 'textfield',name:'wangdianPhoto',id:'wangdianPhoto',fieldLabel: '网点照片路径',width: 250,allowBlank:false,blankText: '',value:(row?row.get("wangdianPhoto"):"")},
			{xtype: 'textarea',fieldLabel: '备注信息',id: 'beizhu',anchor: '70%',name:'beizhu',height: 90,value:(row?row.get("beizhu"):"")}
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(wangdian_win.getComponent('wangdian_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (wangdian_win.getComponent('wangdian_form').form.isValid()) {
					wangdian_win.getComponent('wangdian_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_wangdianInfoSave.asp?sType=add',
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加网点信息成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改网点信息成功!');
								}
								wangdian_win.getComponent('wangdian_form').form.reset();
								wangdian_search.load({params: {start: 0,limit:20}});
								wangdian_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加网点信息失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改网点信息失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							wangdian_search.load({params: {start: 0}});
							wangdian_win.getComponent('wangdian_form').form.reset();
							//wangdian_win.getComponent('wangdian_form').findById("hall_ezmarker").reset();
						}
						
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				wangdian_win.close();
			}
		}]
	});
}

function wangdianAddressLnglat(point,zoom)
{
	LTEvent.removeListener(ezmarkerEvent);
	Ext.getDom("wangdianAddressLng").value = point.getLongitude();
	Ext.getDom("wangdianAddressLat").value = point.getLatitude();
	document.getElementById("ezmarkerDiv").style.display = "none";
}

//--------------------------------网点信息管理结束-------------------------------------------------	


//--------------------------------部门管理开始-------------------------------------------------	
var department_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var department_cm = new Ext.grid.ColumnModel([department_sm,
	{header:'编号',dataIndex:'id',hidden:true},
	{header:'部门类别ID',dataIndex:'departmentTypeID'},
	{header:'部门名称',dataIndex:'departmentName'}
	
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_department = new Ext.data.HttpProxy({url:'json_departmentInfoSearch.asp'});
var reader_department = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'departmentTypeID'},
		{name:'departmentName'}
		
	]
);
//构建Store
department_search = new Ext.data.Store({
	proxy:proxy_department,
	reader:reader_department
});

var grid_department = new Ext.grid.GridPanel({
	store: department_search,
	cm: department_cm,
	loadMask: true,
	//closable: true,
	title: '部门管理列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:department_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'departmentKeyWord',name:'departmentKeyWord',allowBlank: true,emptyText: "搜部门名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				department_search.removeAll();
				department_search.load({
					params:{
						start: 0,
						limit:20,
						departmentKeyWord:grid_department.getTopToolbar().findById("departmentKeyWord").getValue()
					},callback:function(r,options,success){if(department_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{
			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				department_form_obj = getDepartmentForm();
				department_win = new Ext.Window({title: "添加部门信息",width: 360,height: 270,modal: true,maximizable:false,resizable:false,items: department_form_obj});
				department_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				var row = grid_department.getSelectionModel().getSelections();
				if (!row){return;}
				for (var i = 0; i < row.length; i++)
				{
					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
					department_form_obj = getDepartmentForm(row[i]);
					department_win = new Ext.Window({title: "修改部门信息",width: 360,height: 270,modal: true,maximizable:false,resizable:false,items: department_form_obj});
					department_win.show();
					//field = hall_form_obj.getForm().findField('icon');
					//field.setValue(row[i].get("icon"));//new
					//alert(row[i].get("icon"))
				}
			}
		},
		{xtype: "tbseparator"},
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_department.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_departmentInfoSave.asp?sType=del',
									params: 'id=' + row[i].get("id")
								});
							}
							department_search.removeAll();
							department_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		}
	]
});

//生成新加机构点的菜单
function getDepartmentForm(row)
{
	//网点数据结束
	return new Ext.FormPanel({
		id: 'department_form',
		name: 'department_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 350,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		items: [
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'departmentTypeID',fieldLabel: '部门类型ID',width:150,allowBlank:false,blankText: '部门类型ID不能为空',value:(row?row.get("departmentTypeID"):"")},
			{xtype: 'textfield',name:'departmentName',fieldLabel: '部门名称',width:150,allowBlank:false,blankText: '部门名称不能为空',value:(row?row.get("departmentName"):"")}
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(customerInfo_win.getComponent('hall_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (department_win.getComponent('department_form').form.isValid()) {
					department_win.getComponent('department_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_departmentInfoSave.asp?sType=add',
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加部门信息成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改部门信息成功!');
								}
								department_win.getComponent('department_form').form.reset();
								department_search.load({params: {start: 0,limit:20}});
								department_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加部门信息失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改部门信息失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							department_search.load({params: {start: 0}});
							department_win.getComponent('department_form').form.reset();
							//customerInfo_win.getComponent('department_form').findById("hall_ezmarker").reset();
						}
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				department_win.close();
			}
		}]
	});
}

//--------------------------------部门管理结束-------------------------------------------------	



//--------------------------------职位管理开始-------------------------------------------------	
var position_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var position_cm = new Ext.grid.ColumnModel([position_sm,
	{header:'编号',dataIndex:'id',hidden:true},
	{header:'职位类别ID',dataIndex:'positionTypeID'},
	{header:'职位名称',dataIndex:'positionName'}
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_position = new Ext.data.HttpProxy({url:'json_positionInfoSearch.asp'});
var reader_position = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'positionTypeID'},
		{name:'positionName'}
	]
);
//构建Store
position_search = new Ext.data.Store({
	proxy:proxy_position,
	reader:reader_position
});

var grid_position = new Ext.grid.GridPanel({
	store: position_search,
	cm: position_cm,
	loadMask: true,
	//closable: true,
	title: '职位管理列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:position_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'positionKeyWord',name:'positionKeyWord',allowBlank: true,emptyText: "搜职位名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				position_search.removeAll();
				position_search.load({
					params:{
						start: 0,
						limit:20,
						positionKeyWord:grid_position.getTopToolbar().findById("positionKeyWord").getValue()
					},callback:function(r,options,success){if(position_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{
			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				position_form_obj = getPositionForm();
				position_win = new Ext.Window({title: "添加职位信息",width: 360,height: 270,modal: true,maximizable:false,resizable:false,items: position_form_obj});
				position_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				var row = grid_position.getSelectionModel().getSelections();
				if (!row){return;}
				for (var i = 0; i < row.length; i++)
				{
					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
					position_form_obj = getPositionForm(row[i]);
					position_win = new Ext.Window({title: "修改职位信息",width: 360,height: 270,modal: true,maximizable:false,resizable:false,items: position_form_obj});
					position_win.show();
					//field = hall_form_obj.getForm().findField('icon');
					//field.setValue(row[i].get("icon"));//new
					//alert(row[i].get("icon"))
				}
			}
		},
		{xtype: "tbseparator"},
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_position.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_positionInfoSave.asp?sType=del',
									params: 'id=' + row[i].get("id")
								});
							}
							position_search.removeAll();
							position_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		}
	]
});

//生成新加机构点的菜单
function getPositionForm(row)
{
	//网点数据结束
	return new Ext.FormPanel({
		id: 'position_form',
		name: 'position_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 350,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		items: [
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'positionTypeID',fieldLabel: '职位类型ID',width:150,allowBlank:false,blankText: '职位类型ID不能为空',value:(row?row.get("positionTypeID"):"")},
			{xtype: 'textfield',name:'positionName',fieldLabel: '职位名称',width:150,allowBlank:false,blankText: '职位名称不能为空',value:(row?row.get("positionName"):"")}
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(customerInfo_win.getComponent('hall_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (position_win.getComponent('position_form').form.isValid()) {
					position_win.getComponent('position_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_positionInfoSave.asp?sType=add',
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加职位信息成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改职位信息成功!');
								}
								position_win.getComponent('position_form').form.reset();
								position_search.load({params: {start: 0,limit:20}});
								position_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加职位信息失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改职位信息失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							position_search.load({params: {start: 0}});
							position_win.getComponent('position_form').form.reset();
							//customerInfo_win.getComponent('position_form').findById("hall_ezmarker").reset();
						}
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				position_win.close();
			}
		}]
	});
}

//--------------------------------职位管理结束-------------------------------------------------	




//--------------------------------公共方法开始-------------------------------------------------	

//-------------全国城市列表开始-----------------------------
//城市列表窗口，参数type为树是否有复选框，1表示没有，2表示有
function citysWin(fun,type)
{
	citys_form_obj = citysForm(fun,type);
	citys_win = new Ext.Window({title: "城市列表",width: 213,height:375,modal: true,maximizable: false,resizable:false,items: citys_form_obj});
	citys_win.show();
}
function citysForm(fun,type)
{
	if(typeof type == "undefined" || type !=2 || type ==1)
	{
		var treeJSON = citys_tree_obj;
	}
	else
	{
		var treeJSON = citys_tree_obj_checked;
	}
	//全国的城市列表
	var treeCitys = new Ext.tree.TreePanel({
		//el: 'tree',
		//loader: new Ext.tree.TreeLoader({dataUrl:"citys/tree.asp"}),
		loader: new Ext.tree.TreeLoader(),
		//title: '系统管理',
		split: true,
		//border: true,
		rootVisible:false,
		autoScroll: true,
		//autoScroll:false,
		//collapsible: true,
		enableAllCheck:true,	//给树增加复选框
		width: 200,
		height:300
		//,
		//minSize: 80
	});
	
	var root = new Ext.tree.AsyncTreeNode({
		text:'root'
		,
		children: treeJSON
	});
	
	// 设置树的点击事件
	function treeClick(node, e)
	{
		//alert(node.text);
		
		//获取所有子节点
		/*node.cascade( function( node ){
			node.attributes.checked = flag;
			node.ui.checkbox.checked = flag;
			return true;
		});*/
		nodeCity = [];
		nodeCity.push(node.text);
		try
		{
			//获取所有父节点
			var pNode = node.parentNode;
			for(;pNode.id !="root";pNode = pNode.parentNode ){
				//alert(pNode.text);
				if (treeCitys.getChecked(id, node.parentNode) == "")
				{
					//alert(pNode.text);
					if(pNode.text!="root"&&pNode.text!="全国")
					{
						nodeCity.push(pNode.text);
					}
					//pNode.ui.checkbox.checked = flag;
					//pNode.attributes.checked = flag;
				}
			}
		}catch(e){}
	}
	// 增加鼠标单击事件
	treeCitys.on('click', function(node,e){
		nodeCity = [];
		nodeCity.push(node.text);
		try
		{
			//获取所有父节点
			var pNode = node.parentNode;
			for(;pNode.id !="root";pNode = pNode.parentNode ){
				if (treeCitys.getChecked(id, node.parentNode) == "")
				{
					if(pNode.text!="root"&&pNode.text!="全国")
					{
						nodeCity.push(pNode.text);
					}
				}
			}
		}catch(e){}							   
	});
	// 增加复选框架单击事件
	treeCitys.on('checkchange', function(node, checked){
		
		//nodeCityChecked = [];
		
		if(checked == false)
		{
			removeStr(nodeCityChecked,node.text);	
			return;
		}
		
		nodeCityChecked.push(node.text);
		/*try	//预留防止客户更改业务
		{
			//获取所有父节点
			var pNode = node.parentNode;
			for(;pNode.id !="root";pNode = pNode.parentNode ){
				alert(pNode.text);
				if (checked || treeCitys.getChecked(id, node.parentNode) == "")
				{
					if(pNode.text!="root"&&pNode.text!="全国")
					{
						nodeCityChecked.push(pNode.text);
					}
					pNode.ui.checkbox.checked = checked;
					pNode.attributes.checked = checked;
				}
			}
		}catch(e){}*/
	});
	
	treeCitys.setRootNode(root);
	treeCitys.expand();
	//root.reload();
	//Ajax提交新增请求后，在callback中刷新treeCitys的根节点，然后定位到当前节点
	//var path = currentNode.getPath('id');
	//treeCitys.getRootNode().reload();	//刷新树
	//treeCitys.expandPath(path,'id');
	
	var nodeCity = [];	//不带复选框返回的值
	var nodeCityChecked = [];	//带复选框返回的值
	var form1 = new Ext.form.FormPanel({
		width:200,
		//height:200,
		//frame:true,//圆角和浅蓝色背景
		//renderTo:Ext.getBody(),//呈现
		//title:"FormPanel",
		//bodyStyle:"padding:5px 5px 0",
		//defaults:{xtype:"textfield",width:120},
		items:[
			treeCitys
		],
		buttons:[
			{text:"确定",handler:function(){
				if(typeof type == "undefined" || type !=2 || type ==1)
				{
					//不带复选框返回的值
					fun(nodeCity);
				}
				else
				{
					//带复选框返回的值
					fun(nodeCityChecked);
				}
				
				citys_win.close()}
			},
			{text:"取消",handler:function(){citys_win.close()}}]
	});
	return form1;
}

//-------------全国城市列表结束-----------------------------

function indexOfStr(val,text){
	for(var i = 0; i < val.length; i++)
	{
		if(val[i] == text)return i;
	}
	return -1;
}
function removeStr(val,text){
	var index = indexOfStr(val,text);
	if (index > -1) {
		val.splice(index, 1);
	}
}








//将JSON对象转换成字符串
function obj2str(o){
	var r = [];
	if(typeof o =="string") return "\""+o.replace(/([\'\"\\])/g,"\\$1").replace(/(\n)/g,"\\n").replace(/(\r)/g,"\\r").replace(/(\t)/g,"\\t")+"\"";
	if(typeof o =="undefined") return "";
	if(typeof o == "object"){
		if(o===null) return "null";
		else if(!o.sort){
			for(var i in o)
				r.push(i+":"+obj2str(o[i]))
			r="{"+r.join()+"}"
		}else{
			for(var i =0;i<o.length;i++)
				r.push(obj2str(o[i]))
			r="["+r.join()+"]"
		}
		return r;
	}
	return o.toString();
}
//--------------------------------公共方法结束-------------------------------------------------